<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Collector演示 :: Antora Docs</title>
    <meta name="generator" content="Antora 3.2.0-alpha.8">
    <link rel="stylesheet" href="../../../_/css/site.css">
  </head>
  <body class="article">
<header class="header">
  <nav class="navbar">
    <div class="navbar-brand">
      <a class="navbar-item" href="../../..">Antora Docs</a>
      <button class="navbar-burger" aria-controls="topbar-nav" aria-expanded="false" aria-label="Toggle main menu">
        <span></span>
        <span></span>
        <span></span>
      </button>
    </div>
    <div id="topbar-nav" class="navbar-menu">
      <div class="navbar-end">
        <a class="navbar-item" href="#">Home</a>
        <div class="navbar-item has-dropdown is-hoverable">
          <a class="navbar-link" href="#">Products</a>
          <div class="navbar-dropdown">
            <a class="navbar-item" href="#">Product A</a>
            <a class="navbar-item" href="#">Product B</a>
            <a class="navbar-item" href="#">Product C</a>
          </div>
        </div>
        <div class="navbar-item has-dropdown is-hoverable">
          <a class="navbar-link" href="#">Services</a>
          <div class="navbar-dropdown">
            <a class="navbar-item" href="#">Service A</a>
            <a class="navbar-item" href="#">Service B</a>
            <a class="navbar-item" href="#">Service C</a>
          </div>
        </div>
        <div class="navbar-item">
          <span class="control">
            <a class="button is-primary" href="#">Download</a>
          </span>
        </div>
      </div>
    </div>
  </nav>
</header>
<div class="body">
<div class="nav-container" data-component="component-b" data-version="3.1">
  <aside class="nav">
    <div class="panels">
<div class="nav-panel-menu is-active" data-panel="menu">
  <nav class="nav-menu">
    <button class="nav-menu-toggle" aria-label="Toggle expand/collapse all" style="display: none"></button>
    <h3 class="title"><a href="../index.html">Component B</a></h3>
<ul class="nav-list">
  <li class="nav-item" data-depth="0">
<ul class="nav-list">
  <li class="nav-item" data-depth="1">
    <button class="nav-item-toggle"></button>
    <a class="nav-link" href="../index.html">欢迎</a>
<ul class="nav-list">
  <li class="nav-item" data-depth="2">
    <a class="nav-link" href="../xrefs-demo.html">交叉引用的演示</a>
  </li>
</ul>
  </li>
</ul>
  </li>
  <li class="nav-item" data-depth="0">
<ul class="nav-list">
  <li class="nav-item" data-depth="1">
    <a class="nav-link" href="overview.html">模块1概述</a>
  </li>
  <li class="nav-item is-current-page" data-depth="1">
    <a class="nav-link" href="collector-demo.html">Collector演示</a>
  </li>
  <li class="nav-item" data-depth="1">
    <a class="nav-link" href="distributed-demo.html">分布式组件示例</a>
  </li>
</ul>
  </li>
</ul>
  </nav>
</div>
<div class="nav-panel-explore" data-panel="explore">
  <div class="context">
    <span class="title">Component B</span>
    <span class="version">3.1</span>
  </div>
  <ul class="components">
    <li class="component">
      <div class="title"><a href="../../../component-a/1.6.0/source-code.html">Component A</a></div>
      <ul class="versions">
        <li class="version is-latest">
          <a href="../../../component-a/1.6.0/source-code.html">1.6.0</a>
        </li>
      </ul>
    </li>
    <li class="component is-current">
      <div class="title"><a href="../index.html">Component B</a></div>
      <ul class="versions">
        <li class="version is-current is-latest">
          <a href="../index.html">3.1</a>
        </li>
        <li class="version">
          <a href="../../2.5/index.html">2.5-beta.1</a>
        </li>
        <li class="version">
          <a href="../../2.0/index.html">2.0</a>
        </li>
        <li class="version">
          <a href="../../1.0/index.html">1.0</a>
        </li>
      </ul>
    </li>
  </ul>
</div>
    </div>
  </aside>
</div>
<main class="article">
<div class="toolbar" role="navigation">
<button class="nav-toggle"></button>
  <a href="../index.html" class="home-link"></a>
<nav class="breadcrumbs" aria-label="breadcrumbs">
  <ul>
    <li><a href="../index.html">Component B</a></li>
    <li><a href="collector-demo.html">Collector演示</a></li>
  </ul>
</nav>
<div class="page-versions">
  <button class="version-menu-toggle" title="Show other versions of page">3.1</button>
  <div class="version-menu">
    <a class="version is-current" href="collector-demo.html">3.1</a>
    <a class="version is-missing" href="../../2.5/index.html">2.5-beta.1</a>
    <a class="version is-missing" href="../../2.0/index.html">2.0</a>
    <a class="version is-missing" href="../../1.0/index.html">1.0</a>
  </div>
</div>
</div>
  <div class="content">
<aside class="toc sidebar" data-title="Contents" data-levels="2">
  <div class="toc-menu"></div>
</aside>
<article class="doc">
<h1 class="page">Collector演示</h1>
<div id="preamble">
<div class="sectionbody">
<div class="paragraph">
<p>本页面用于演示 Antora Collector Extension。</p>
</div>
<div class="paragraph">
<p>关于Collector Extension，建议首先阅读<a href="https://docs.antora.org/collector-extension/latest/use-cases/">Antora Collector Extension Documentation</a>。在<a href="../../../component-a/1.6.0/source-code.html" class="xref page">Component A 中的示例</a>是完全按照该文档设计的，这里的方法相同，只是目录和文件名不同。</p>
</div>
<div class="paragraph">
<p>磁盘文件结构如下：</p>
</div>
<div class="literalblock">
<div class="content">
<pre>📂 code
  📄 my_app.rb
📂 docs
  📄 antora.yml
  📂 modules
    📂 module-one
      📄 nav.adoc
      📂 pages
        📄 collector-demo.adoc
        📄 overview.adoc
    📁 ROOT</pre>
</div>
</div>
<div class="paragraph">
<p>我们的目标是将<em>code</em>文件夹作为<em>module-one/examples</em>。</p>
</div>
<div class="paragraph">
<p>在<em>antora.yml</em>中增加如下配置：</p>
</div>
<div class="listingblock">
<div class="content">
<pre>ext:
  collector:
  - scan:
      dir: code
      into: modules/module-one/examples</pre>
</div>
</div>
<div class="paragraph">
<p>此时<em>code</em>中的文件就能够像模块内部的<em>examples</em>文件夹一样使用，代码如下。</p>
</div>
<div class="literalblock">
<div class="content">
<pre>include::example$my_app.rb[]</pre>
</div>
</div>
<div class="paragraph">
<p>效果如下：</p>
</div>
<div class="listingblock">
<div class="title">my_app.rb</div>
<div class="content">
<pre class="highlightjs highlight"><code class="language-ruby hljs" data-lang="ruby"># This file represents "software".
# This file helps show that documentation files can be in the same repository as software.

rescue =&gt; ex
  begin
    context = %(asciidoctor: FAILED: #{attrs['docfile'] || '&lt;stdin&gt;'}: Failed to load AsciiDoc document)
    if ex.respond_to? :exception
      # The original message must be explicitely preserved when wrapping a Ruby exception
      wrapped_ex = ex.exception %(#{context} - #{ex.message})
      # JRuby automatically sets backtrace, but not MRI
      wrapped_ex.set_backtrace ex.backtrace
    else
      # Likely a Java exception class
      wrapped_ex = ex.class.new context, ex
      wrapped_ex.stack_trace = ex.stack_trace
    end
  rescue
    wrapped_ex = ex
  end
  raise wrapped_ex
end</code></pre>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="bm-known-issue"><a class="anchor" href="#bm-known-issue"></a>未成功的尝试</h2>
<div class="sectionbody">
<div class="paragraph">
<p>曾经想将另一个组件Component A的ROOT模块作为本组件（Component B）的demo-a模块，但没有成功，尝试过程见本页面的3.0版。</p>
</div>
<div class="paragraph">
<p>根本原因是“收集”的文件不在同一仓库内。
如果源文件在本地，也能通过编译，显示结果也正常。
但源文件在远程，通过git url获取，想将component-a的文件收集到component-b，编译时会找不到文件。</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_总结"><a class="anchor" href="#_总结"></a>总结</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Antora Collector Extension 可以用于将<strong>同一仓库内</strong>（但不在modules内）的目录“收集”作为modules内的目录使用。
与符号链接（symlink）异曲同工，可以省去在不同的计算机上同步符号链接的麻烦。
美中不足是，在VS CODE中asciidoctor.js会提示语法错误<code>include file not found</code>，但不影响Antora编译。</p>
</div>
</div>
</div>
</article>
  </div>
</main>
</div>
<footer class="footer">
  <p>This page was built using the Antora default UI.</p>
  <p>The source code for this UI is licensed under the terms of the MPL-2.0 license.</p>
</footer>
<script id="site-script" src="../../../_/js/site.js" data-ui-root-path="../../../_"></script>
<script async src="../../../_/js/vendor/highlight.js"></script>
  </body>
</html>
